package com.android.filter;

import android.graphics.Path;

import com.android.filter.jni.VertexInfo;

public class GridInfo {
	PreviewImage mPreviewPath;
	VertexInfo mVertexInfo;
	int mGridType;
	public void destroy()
	{
		freePreviewPath();
		if(mVertexInfo != null)
			mVertexInfo = null;
	}
	public void freePreviewPath()
	{
		if(mPreviewPath != null)
			mPreviewPath.destroy();
		mPreviewPath = null;
	}
	public Path getGridPath()
	{
		Path ret = new Path();
		if(mVertexInfo != null)
		{
			int[] vertices = mVertexInfo.vertices;

			int k = 0;
			for(int stride : mVertexInfo.stride)
			{
				float startX = 0.f;
				float startY = 0.f;
				for(int j = 0 ; j < stride ; j++)
				{
					float x = vertices[k++];
					float y = vertices[k++];
					if(j == 0)
					{
						ret.moveTo(x, y);
						startX = x;
						startY = y;
					}
					else if(j == stride - 1)
					{
						ret.lineTo(x, y);
						ret.lineTo(startX, startY);
					}
					else
						ret.lineTo(x, y);
				}
			}
		}
		return ret;
	}
}
